﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jumpton.SFA.Server.BusinessRule.CallRoute;
using System.Data;

public partial class History : PageBase
{
    protected String Body = "";
    private int uid = -1;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!int.TryParse(Request.QueryString[CommonString.UID], out uid))
            return;
        //控制访问权限暂未添加
        InitPage();

    }

    private void InitPage()
    {
        
        try
        {
            RouteManager routeManager = new RouteManager();
            DataTable dt = routeManager.GetUserHistoryVisitList(uid);
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            String HeaderFormat = "<li><h3>{0}</h3><p> 访问量：{1}家&nbsp;&nbsp; 达成率：{2} </p>";
            String ItemFormat = "<li>{0}{1}</li>";
            String DetailContentFormat = "<ul data-role=\"listview\"><li><a href=\"VisitBasicInfo.aspx?{0}\" >基本信息</a></li><li><a href=\"Visit_KPI_Info.aspx?{0}\" >指标信息</a></li><li><a href=\"Visit_CPR_Info.aspx?{0}\" >分销数据</a></li><li><a href=\"VisitPhotoInfo.aspx?{0}\">照片</a></li></ul>";
           
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                String dateTime = Jumpton.SFA.Server.BusinessRule.BusinessLogic.GetDateTime(dt.Rows[i]["visit_date"].ToString(), "yyyyMMdd", "yyyy-MM-dd");

                sb.Append(String.Format(HeaderFormat, dateTime, dt.Rows[i]["visitNumber"], dt.Rows[i]["fact_visit_percent"]));
                sb.Append("<ol data-role=\"listview\">");
                DataTable itemTable = routeManager.GetVisitListByUserAndDate(uid, dt.Rows[i]["visit_date"].ToString());
                for (int j = 0; j < itemTable.Rows.Count; j++)
                {
                    //验证字符串
                    System.Collections.Specialized.NameValueCollection newlist = QueryStringHelper.DecodeQueryString(Request.QueryString);
                    newlist.Add("visitid", itemTable.Rows[j]["ID"].ToString());
                    newlist.Add(CommonString.REQUESTKEY, QueryStringHelper.BuilderRequestKey(newlist, VERSION));
                    String QueryString = QueryStringHelper.BuilderQueryString(newlist);
                    sb.Append(String.Format(ItemFormat, itemTable.Rows[j]["NAME"], String.Format(DetailContentFormat,QueryString)));
                }
                sb.Append("</ol></li>");

            }

            

            Body = sb.ToString();
            this.DataBind();
        }
        catch (Exception err)
        {

        }

    }
}